import 'package:aweb5/pages/plan_detail.dart';
import 'package:aweb5/util/NaviUtil.dart';
import 'package:flutter/material.dart';
import 'package:aweb5/Para.dart';
import 'package:path/path.dart';
import 'today_plan.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:aweb5/pages/pub_material.dart';
import 'package:aweb5/pages/plan_material.dart';
import 'package:aweb5/pages/my_material.dart';
import 'package:aweb5/pages/material_lib.dart';

///今日素材
class PlanMaterial extends StatefulWidget {
  @override
  _PlanMaterialState createState() => _PlanMaterialState();
}

class _PlanMaterialState extends State<PlanMaterial> {
  int currentTab = 0;

  BuildContext context;

//  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    this.context = context;
    return Stack(
      children: <Widget>[
        Scaffold(
          body: Stack(
            children: <Widget>[
              buildBody(),
            ],
          ),
          bottomNavigationBar: bottomAppBar(),
        ),
        Positioned(
          child: GestureDetector(
            child: Image.asset(
              "assets/assist/tianjia.png",
              width: ScreenUtil().setHeight(55),
              height: ScreenUtil().setHeight(55),
            ),
            onTap: () {
              NaviUtil.push(context, PlanDetail(null, null,"", url:"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2263502137,4060353372&fm=26&gp=0.jpg"));
            },
          ),
          bottom: ScreenUtil().setHeight(73 - 27.5),
          right:
              ScreenUtil().setWidth(414 / 3 / 2) - ScreenUtil().setHeight(27.5),
        ),
      ],
    );
  }

  GlobalKey<TodayplanState> todayplankey = GlobalKey();
  Widget buildBody() {
    if (currentTab == 0) {
//      Todayplan todayplan = Todayplan(todayplankey);

//      todayplankey.currentState?.request();
      return Todayplan();
//      return Text("");
    } else {
      return MaterialLib();
    }
  }
//底部
  Widget bottomAppBar() {
    return Visibility(
        visible: true,
        child: BottomAppBar(
//          child:

//          Padding(
//            padding: EdgeInsets.fromLTRB(
//                0, ScreenUtil().setHeight(0), 0, ScreenUtil().setHeight(0)),
          child: Container(
            height: ScreenUtil().setHeight(73),
            width: ScreenUtil().setWidth(414),
            child: Row(
              children: <Widget>[
                Flexible(
                  child: Row(
                    mainAxisSize: MainAxisSize.max,
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: <Widget>[
                      GestureDetector(
                          onTap: () {
                            //  toast("${index}");
                            currentTab = 0;
                            setState(() {});
                          },
                          child: Column(
                            mainAxisSize: MainAxisSize.min,
                            children: <Widget>[
                              getIcon1(0),
                              SizedBox(
                                height: ScreenUtil().setHeight(7),
                              ),
                              getTitle1(0),
                              SizedBox(
                                height: ScreenUtil().setHeight(7),
                              ),
                              Container(
                                height: ScreenUtil().setHeight(5),
                                width: ScreenUtil().setWidth(71),
                                color: currentTab==0?Color(0xffF94F68):Colors.transparent,
                              )
                            ],
                          )),
                      GestureDetector(
                          onTap: () {},
                          child: GestureDetector(
                            child: Column(
                              mainAxisSize: MainAxisSize.min,
                              children: <Widget>[
                                getIcon1(1),
                                SizedBox(
                                  height: ScreenUtil().setHeight(7),
                                ),
                                getTitle1(1),
                                SizedBox(
                                  height: ScreenUtil().setHeight(7),
                                ),
                                Container(
                                  height: ScreenUtil().setHeight(5),
                                  width: ScreenUtil().setWidth(71),
                                  color: currentTab==1?Color(0xffF94F68):Colors.transparent,
                                )
                              ],
                            ),
                            onTap: () {
                              currentTab = 1;
                              setState(() {});
                            },
                          )),
                    ],
                  ),
                  flex: 2,
                ),
                Flexible(
                  child: Container(
                    height: ScreenUtil().setHeight(73),
//                    width: ScreenUtil().setWidth(Para.width / 3),
                    width: ScreenUtil().setWidth(414 / 3),
//                      padding: EdgeInsets.only(bottom: ScreenUtil().setHeight(1)),
                    alignment: Alignment.center,
                    child: GestureDetector(
                      child: Column(
                        children: <Widget>[
                          Expanded(
                            flex: 1,
                            child: Text(""),
                          ),
                          Text("添加素材",
                              style: TextStyle(
                                  color: Color(0xffF94F68),
                                  fontSize: ScreenUtil().setSp(16),fontWeight: FontWeight.bold)),
                          SizedBox(
                            height: ScreenUtil().setHeight(12),
                          )
                        ],
                      ),
                      onTap: () {
                        NaviUtil.push(context, PlanDetail(null, null, "",url: "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2263502137,4060353372&fm=26&gp=0.jpg",from: "tianjiasucai",));
                      },
                    ),
                  ),
                  flex: 1,
                )
              ],
            ),
          ),
//          ),
        ));
  }

  Widget getIcon1(int index) {
    if (index == 0) {
      if (currentTab == index) {
        return Container(
          width: ScreenUtil().setHeight(24),
          height: ScreenUtil().setHeight(24),
          alignment: Alignment.bottomCenter,
          child: Image.asset(
            "assets/assist/shijianhong.png",
            width: ScreenUtil().setHeight(24),
            height: ScreenUtil().setHeight(24),
            fit: BoxFit.fill,
          ),
        );
      } else {
        return Container(
          width: ScreenUtil().setHeight(24),
          height: ScreenUtil().setHeight(24),
          alignment: Alignment.bottomCenter,
          child: Image.asset(
            "assets/assist/shijianhui.png",
            width: ScreenUtil().setHeight(24),
            height: ScreenUtil().setHeight(24),
            fit: BoxFit.fill,
          ),
        );
      }
    }

    if (index == 1) {
      if (currentTab == index) {
        return Container(
          width: ScreenUtil().setHeight(24),
          height: ScreenUtil().setHeight(24),
          alignment: Alignment.bottomCenter,
          child: Image.asset(
            "assets/assist/wenjianhong.png",
            width: ScreenUtil().setHeight(24),
            height: ScreenUtil().setHeight(24),
            fit: BoxFit.fill,
          ),
        );
      } else {
        return Container(
          width: ScreenUtil().setHeight(24),
          height: ScreenUtil().setHeight(24),
          alignment: Alignment.bottomCenter,
          child: Image.asset(
            "assets/assist/wenjian.png",
            width: ScreenUtil().setHeight(24),
            height: ScreenUtil().setHeight(24),
            fit: BoxFit.fill,
          ),
        );
      }
    }
  }

  Widget getTitle1(int index) {
    if (index == 0) {
      if (currentTab == index) {
        return Text("今日计划",
            style: TextStyle(
                color: Color(0xffF94F68), fontSize: ScreenUtil().setSp(16),fontWeight: FontWeight.bold));
      } else {
        return Text("今日计划",
            style: TextStyle(
                color: Color(0xff686868), fontSize: ScreenUtil().setSp(16),fontWeight: FontWeight.bold));
      }
    }
    if (index == 1) {
      if (currentTab == index) {
        return Text("素材库",
            style: TextStyle(
                color: Color(0xffF94F68), fontSize: ScreenUtil().setSp(16),fontWeight: FontWeight.bold));
      } else {
        return Text("素材库",
            style: TextStyle(
                color: Color(0xff686868), fontSize: ScreenUtil().setSp(16),fontWeight: FontWeight.bold));
      }
    }
  }
}
